/*
 * Copyright 2012 JooKar BV (info@jookar.nl)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.jookar.android.simpleclock;

import java.util.Date;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import android.view.WindowManager;

/**
 * @author Joost A. Bloemsma
 *
 */
public class SimpleClockActivity extends Activity {
	private IClockView clock;
	private static final int TICK_WHAT = 2;
	private int refreshInterval = 1000;
	
	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message m) {
			tick();
			sendMessageDelayed(Message.obtain(this, TICK_WHAT), refreshInterval);
		}
	};
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
         
        setContentView(R.layout.main);
        
        clock = (IClockView)findViewById(R.id.clockView);
        clock.set24H(true);
        start();
    }
    
    /**
     * The 'tick' of the clock. Get's triggered every interval.
     */
    public void tick() {
    	clock.setTime(new Date());
    }
    
    private void start() {
    	handler.sendMessageAtTime(Message.obtain(handler, TICK_WHAT), 1);
    }
    
}